package com.whynot.frame.basic.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 描    述:重定向工具类
 * 创建时间: 2018/06/30
 */
public class RedirectUtil {

    private static final Logger LOGGER = LoggerFactory.getLogger(RedirectUtil.class);

    /**
     * 重定向对应的url
     * @param req
     * @param resp
     * @param url
     */
    public static void toResponse(ServletRequest req, ServletResponse resp,String url) {
        try {
            HttpServletResponse httpServletResponse = (HttpServletResponse) resp;
            httpServletResponse.sendRedirect("/"+url);
        } catch (IOException e) {
            LOGGER.error(e.getMessage());
        }
    }
}